package com.springboot.controller.open;

import com.springboot.aop.TokenatureValidation;
import com.springboot.utils.ResultUtil;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/test")
@Slf4j
@Api
public class TestContriller {

	@TokenatureValidation
	@PostMapping("/testdome")
	@ApiOperation(value = "test√", notes = "返回JSON数据")
	@ApiOperationSupport(
			responses = @DynamicResponseParameters(properties = {
					@DynamicParameter(name = "code", value = "状态码:100.失败 200.成功"),
					@DynamicParameter(name = "msg", value = "系统返回信息"),
			})
	)
	@ApiImplicitParams({
			@ApiImplicitParam(paramType = "query", dataType="String", name = "test1", value = "测试值1", required = true),
			@ApiImplicitParam(paramType = "query", dataType="String", name = "test2", value = "测试值2", required = true),
			@ApiImplicitParam(paramType = "body", dataType="file", name = "merCertFile", value = "商户私钥证书文件(二选一)", required = false),

	})
	public Map<String, Object> testdome(@RequestParam(value = "test1", required = true, defaultValue = "") String test1,
										@RequestParam(value = "merCertFile", required = false) MultipartFile merCertFile,
										@RequestParam(value = "test2", required = true, defaultValue = "") String test2) {
		Map<String, Object> map = new HashMap<>();
		try {
			map.put("code", 200);
			map.put("test1", test1);
			map.put("test2", test2);
			map.put("msg", "测试成功");
		} catch (Exception e) {
			e.printStackTrace();
			map.put("code", 100);
			map.put("msg", "系统异常");
		}
		return map;
	}

	@PostMapping(value = "/testdome1")
	@ApiOperation(value = "testdome1", notes = "testdome1")
	@ApiOperationSupport(
			responses = @DynamicResponseParameters(properties = {
					@DynamicParameter(name = "code", value = "状态码:100.失败 200.成功"),
					@DynamicParameter(name = "msg", value = "系统返回信息"),
			})
	)
	@ApiImplicitParams({@ApiImplicitParam(paramType = "body", dataType = "String", name = "json", value = "密码", required = true)})
	public ResultUtil login1(@RequestBody  String json) {
		System.out.println(json);
		return ResultUtil.Success(json);
	}

}
